#include <stdio.h>
#include <cassert>
#include <string.h>
#include <inttypes.h>

using namespace std;
#include "cbp3_def.h"
#include "cbp3_framework.h"

// branch always taken "predictor" (for conditional and indirect branches)

void PredictorInit() {
    // nothing to init
}

void PredictorReset() {
    printf("Predictor: always taken\n");
}

void PredictorRunACycle() {
    // get info about what uops are processed at each pipeline stage
    const cbp3_cycle_activity_t *cycle_info = get_cycle_info();

    // make prediction at fetch stage
    for (int i = 0; i < cycle_info->num_fetch; i++) {
        uint32_t fe_ptr = cycle_info->fetch_q[i];
        const cbp3_uop_dynamic_t *uop = &fetch_entry(fe_ptr)->uop;

        if ( uop->type & IS_BR_CONDITIONAL ) {
            assert(report_pred(fe_ptr, false, true));
        }else if ( uop->type & IS_BR_INDIRECT ) {
            assert(report_pred(fe_ptr, false, true)); //FIXME: target?
        }
    }
}

void PredictorRunEnd() {
    // nothing
}

void PredictorExit() {
    // nothing
}
